using System.Collections.Generic;

namespace ColladaDotNet
{
	public partial class morph : ColladaXmlNode
	{
		public override IList<ColladaXmlNode> ChildNodes
		{
			get
			{
				var list = new List<ColladaXmlNode>();
				if (source != null)
					foreach (object e in source) if (e is ColladaXmlNode) list.Add((ColladaXmlNode)e);
				if (extra != null)
					foreach (object e in extra) if (e is ColladaXmlNode) list.Add((ColladaXmlNode)e);
				if (targets != null)
					list.Add(targets);
				return list;
			}
		}

		public source CreateTargetsSource(string id, string[] strings)
		{
			var res = new source();
			res.id = id;
			res.Item = new Name_array() {count = (ulong)strings.Length, id = id + "-array", Text = strings};
			res.technique_common = new sourceTechnique_common() { accessor = new accessor() { source = "#" + id + "-array" ,count = (ulong)strings.Length,param = new param[]{new param(){type = "name"} }} };
			source = COLLADA.AddToArray(source, res);
			return res;
		}

		public source CreateZeroWeights(string id, int count)
		{
			var res = new source();
			res.id = id;
			double[] arr = new double[count];
			res.Item = new float_array() { count = (ulong)count, id = id + "-array", Text = arr };
			res.technique_common = new sourceTechnique_common() { accessor = new accessor() { source = "#" + id + "-array", count = (ulong)count, param = new param[] { new param() { type = "float",name = "WEIGHT"} } } };
			source = COLLADA.AddToArray(source, res);
			return res;
		}

		public InputLocal CreateTargetInput(source source2)
		{
			if (targets == null)
				targets = new morphTargets();
			InputLocal res = new InputLocal() {semantic = "MORPH_TARGET", source = "#" + source2.id};
			targets.input = COLLADA.AddToArray(
					targets.input, res);
			return res;
		}
		public InputLocal CreateWeightInput(source source2)
		{
			if (targets == null)
				targets = new morphTargets();
			InputLocal res = new InputLocal() { semantic = "MORPH_WEIGHT", source = "#" + source2.id };
			targets.input = COLLADA.AddToArray(
					targets.input, res);
			return res;
		}
	}
}
